package com.tyj.movie.config.interceptor;

import com.tyj.movie.entity.City;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 日期: 2021/7/12 11:39
 * 作者: 谭友杰
 * 类说明: 城市拦截器
 */
public class CityInterceptor implements HandlerInterceptor {

    public static ThreadLocal<City> threadLocal = new ThreadLocal<>();

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //该出可以通过gps定位获取城市
        HttpSession session = request.getSession();
        City city = new City();
        city.setName("长沙");
        city.setId(1);
        if (session.getAttribute("city")==null){
            session.setAttribute("city", city);

        }
        threadLocal.set(city);

        return true;
    }
}
